package com.imocc.service.impl;

import com.imocc.Dao.ProductinfoDao;
import com.imocc.dataobject_PO.ProductInfo;
import com.imocc.enums.ProductStatusEnum;
import com.imocc.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 王志鹏
 * @Date 2019/3/3 11:17
 **/
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductinfoDao productinfoDao;

    @Override
    public ProductInfo findOne(String productId) {
        return productinfoDao.findOne(productId);
    }

    @Override
    public List<ProductInfo> findUpAll() {
        // 使用 枚举 来控制集中管理有更好的并有更好的注释
        return productinfoDao.findByProductStatus(ProductStatusEnum.UP.getCode());
    }

    @Override
    public Page<ProductInfo> findAll(Pageable pageable) {

        Page<ProductInfo> productInfoPage = productinfoDao.findAll(pageable);
//        productInfoPage.getContent().stream().forEach(e -> e.addImageHost(upYunConfig.getImageHost()));
        return productInfoPage;
    }

    @Override
    public ProductInfo save(ProductInfo productInfo) {

        return productinfoDao.save(productInfo);
    }
}
